<template>
  <div class="talent-detail-page">
    <ul class="list">
      <li>
        <h2>
          <span class="tit">{{ keyword }}</span>
        </h2>
        <p class="abst">{{ textList }}</p>
        <ul class="child-list">
          <li v-for="(child, index) in patentList" :key="index">
            <i class="circle"></i>
            <div class="panel">
              <h4>{{ child.isd }}</h4>
              <div class="box">
                <h3>
                  <span class="tit">{{ child.ttl }}</span>
                  <span class="tag status1">{{ child.pn }}</span>
                </h3>
                <p
                  class="abs"
                  v-html="
                    child.abst && child.abst.length > 300 && !child.toggle
                      ? child.abst.substr(0, 300) + '...'
                      : child.abst
                  "
                ></p>
                <span
                  v-if="child.abst && child.abst.length > 300"
                  class="toggle"
                  @click="toggleAbs(child)"
                  >{{ child.toggle ? "收起" : "展开" }}</span
                >
              </div>
            </div>
          </li>
        </ul>
      </li>
    </ul>
    <!-- 分页 -->
    <div class="pagination">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="total"
        :page-size="pageSize"
        :current-page.sync="pageNum"
        @current-change="getOneCurrentPage"
        class="el-pagination"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    keyword: {
      type: String,
    },
  },
  data() {
    return {
      patentList: [],
      textList: "",
      pageSize: 10,
      pageNum: 1,
      total: 0,
    };
  },
  mounted() {
    this.getTextList(this.keyword);
    this.getPatentList(this.keyword);
  },
  methods: {
    getTextList(keyword) {
      const params = {
        keyword: keyword,
      };
      this.$get(this.$Url.technology.textList, params).then((res) => {
        this.textList = res.data ? res.data.text : "";
      });
    },
    getPatentList(keyword) {
      this.patentList = [];
      const params = {
        ipi: this.pageNum,
        ips: this.pageSize,
        keyword: keyword,
      };
      this.$get(this.$Url.technology.patentList, params).then((res) => {
        if (res.data) {
          res.data.result.map((item) => {
            this.patentList = [
              ...this.patentList,
              {
                ...item,
                toggle: false,
              },
            ];
          });
        }
        this.pageNum = res.data ? res.data.pageNum : 1;
        this.pageSize = res.data ? res.data.pageSize : 10;
        this.total = res.data ? res.data.total : 0;
      });
    },
    toggleAbs(item) {
      item.toggle = !item.toggle;
    },
    getOneCurrentPage(val) {
      this.pageNum = val;
      this.getPatentList(this.keyword);
    },
  },
};
</script>

<style lang="scss" scoped>
.talent-detail-page {
  position: relative;
  text-align: left;
  background-color: #fff;
  .list {
    position: relative;
    padding-left: 0;
    padding-top: 40px;
    margin-left: 20px;
    margin-right: 40px;
    list-style: none;
    h2 {
      margin-bottom: 16px;
      .tit {
        font-size: 20px;
        color: #241c75;
        // cursor: pointer;
      }
      .tag {
        float: right;
        line-height: 28px;
        padding: 0 15px;
        border-radius: 4px;
        font-weight: normal;
        font-size: 14px;
        color: #fff;
        &.status1 {
          background-color: #41b3a2;
        }
        &.status2 {
          background-color: #c44b5c !important;
        }
      }
    }
    .abst {
      line-height: 24px;
      margin-bottom: 24px;
      font-size: 14px;
      color: #7674a3;
    }
    li {
      position: relative;
      padding-left: 36px;
      padding-bottom: 40px;
      &:last-of-type {
        padding-bottom: 0;
      }
      ul {
        li {
          border-left: 1px solid #65c6f5;
        }
      }
      .circle {
        position: absolute;
        top: 0;
        left: -5px;
        display: block;
        width: 10px;
        height: 30px;
        background-color: #fff;
        &:before {
          position: absolute;
          top: 10px;
          left: 0;
          width: 10px;
          height: 10px;
          border-radius: 50%;
          background-color: #65c6f5;
          content: "";
        }
      }
      .panel {
        position: relative;
        h4 {
          line-height: 30px;
          margin-bottom: 20px;
          font-size: 18px;
          color: #241c75;
        }
        .box {
          padding: 20px 30px;
          background-color: #f7f9fc;
          h3 {
            margin-bottom: 16px;
            .tit {
              font-size: 20px;
              color: #241c75;
              // cursor: pointer;
            }
            .tag {
              float: right;
              line-height: 28px;
              padding: 0 15px;
              border-radius: 4px;
              font-weight: normal;
              font-size: 14px;
              color: #fff;
              &.status1 {
                background-color: #41b3a2;
              }
              &.status2 {
                background-color: #c44b5c !important;
              }
            }
          }
          .patent-number {
            margin-bottom: 16px;
            font-size: 14px;
            color: #7674a3;
            .tit {
              display: inline-block;
              width: 65px;
              color: #241c75;
            }
          }
          .abs {
            line-height: 22px;
            margin-bottom: 24px;
            font-size: 14px;
            color: #7674a3;
          }
          .toggle {
            color: #6f6dd8;
            &:hover {
              opacity: 0.8;
              cursor: pointer;
            }
          }
        }
      }
    }
  }
  .pagination {
    padding: 30px 0;
    text-align: center;
  }
}
</style>